﻿using System;
using System.Windows;

using SBPweb.Forge.Contracts.Extensibility;

namespace SBPweb.Forge.Controls.Silverlight
{

    public class ExtendableApplication : Application, IExtendable
    {

        #region Private fields

        private ExtendableBase extensions = new ExtendableDictionary();

        #endregion

        #region Property accessors

        public T Get<T>(string propertyName)
        {
            return extensions.Get<T>(propertyName);
        }

        public void Put<T>(string propertyName, T value)
        {
            //if (RootVisual != null)
            //{
            //    RootVisual.Dispatcher.BeginInvoke( () =>
            //    {
            //        extensions.Put<T>(propertyName, value);
            //    });
            //}
            //else
            //{
                extensions.Put<T>(propertyName, value);
            //}
        }

        #endregion

        #region Events

        public event EventHandler<PropertyChangedEventArgs> PropertyChanged
        {
            add
            {
                extensions.PropertyChanged += new EventHandler<PropertyChangedEventArgs>(value);
            }
            remove
            {
                extensions.PropertyChanged -= new EventHandler<PropertyChangedEventArgs>(value);
            }
        }

        #endregion

        #region Subclasses

        private class ExtendableDictionary : ExtendableBase
        {
        }

        #endregion

    }

}